package com.hutra.utils {
	import flash.events.*;
	import flash.utils.*;
	import flash.events.TimerEvent;
	import flash.events.Event;
	import flash.external.ExternalInterface;
	
	public class Speeder {
		private var compare:int = 0;
		private var cpu:Timer = new Timer(1000, 60);
		private var second:Date = new Date();
		private var messages:String = new String("System error!");
		
		public function stopTrack():void {
			compare = 0;
			cpu.reset();
			cpu.stop();
		}
		
		public function startTrack():void {
			compare = 0;
			cpu.reset();
			cpu.start();
		}
		
		public function Speeder() {
			compare = second.seconds;
			cpu.addEventListener(TimerEvent.TIMER, dspeed_Time);
			cpu.addEventListener(TimerEvent.TIMER_COMPLETE, dspeed_Complete);
		}
		
		public function setMessages(strmessage:String):void {
			this.messages = strmessage;
		}
		
		public function getMessages():String {
			return this.messages;
		}
		
		private function dspeed_Complete(evt:TimerEvent):void {
			compare = 0;
			evt.target.reset();
			evt.target.start();
		}
		
		private function dspeed_Time(evt:TimerEvent = null):void {
			second = new Date();
			compare++;
			var mini:int = second.seconds;
			if (second.seconds == 0) {
				compare = second.seconds;
			}
			if (compare >= 59) {
				compare = mini;
			}
			
			if (compare > mini) {
				try {
					ExternalInterface.call("plopen.reload", this.getMessages());
				} catch (e) {
					trace("error dspeed_Time:", e);
				}
			}
		}
	}
}